<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>80386 Programmer's Reference Manual -- Section 7.4</TITLE>
</HEAD>
<BODY STYLE="width:80ch">
<B>up:</B> <A HREF="c07.htm">
Chapter 7 -- Multitasking</A><BR>
<B>prev:</B> <A HREF="s07_03.htm">7.3  Task Register</A><BR>
<B>next:</B> <A HREF="s07_05.htm">7.5  Task Switching</A>
<P>
<HR>
<P>
<H1>7.4  Task Gate Descriptor</H1>
A task gate descriptor provides an indirect, protected reference to a TSS.

<A HREF="s07_04.htm#fig7-4">Figure 7-4</A>
  illustrates the format of a task gate.
<P>
The SELECTOR field of a task gate must refer to a TSS descriptor. The value
of the RPL in this selector is not used by the processor.
<P>
The DPL field of a task gate controls the right to use the descriptor to
cause a task switch. A procedure may not select a task gate descriptor
unless the maximum of the selector's RPL and the CPL of the procedure is
numerically less than or equal to the DPL of the descriptor. This constraint
prevents untrusted procedures from causing a task switch. (Note that when a
task gate is used, the DPL of the target TSS descriptor is not used for
privilege checking.)
<P>
A procedure that has access to a task gate has the power to cause a task
switch, just as a procedure that has access to a TSS descriptor. The 80386
has task gates in addition to TSS descriptors to satisfy three needs:
<OL>
<LI> The need for a task to have a single busy bit. Because the busy-bit
is stored in the TSS descriptor, each task should have only one such
descriptor. There may, however, be several task gates that select the
single TSS descriptor.
<LI> The need to provide selective access to tasks. Task gates fulfill
this need, because they can reside in LDTs and can have a DPL that is
different from the TSS descriptor's DPL. A procedure that does not
have sufficient privilege to use the TSS descriptor in the GDT (which
usually has a DPL of 0) can still switch to another task if it has
access to a task gate for that task in its LDT. With task gates,
systems software can limit the right to cause task switches to
specific tasks.
<LI> The need for an interrupt or exception to cause a task switch. Task
gates may also reside in the IDT, making it possible for interrupts
and exceptions to cause task switching. When interrupt or exception
vectors to an IDT entry that contains a task gate, the 80386 switches
to the indicated task. Thus, all tasks in the system can benefit from
the protection afforded by isolation from interrupt tasks.
</OL>

<A HREF="s07_04.htm#fig7-5">Figure 7-5</A>
  illustrates how both a task gate in an LDT and a task gate in
the IDT can identify the same task.
<P>
<A NAME="fig7-4">
<PRE>Figure 7-4.  Task Gate Descriptor</PRE>
<P>
<PRE>
   31                23               15                7             0
  +-----------------+----------------+-+-----+---------+-----------------+
  |##################################| |     |         |#################|
  |############(NOT USED)############|P| DPL |0 0 1 0 1|###(NOT USED)####| 4
  |##################################| |     |         |#################|
  |----------------------------------+-+-----+---------+-----------------|
  |                                  |###################################|
  |              SELECTOR            |############(NOT USED)#############| 0
  |                                  |###################################|
  +-----------------+----------------+-----------------+-----------------+
</PRE>
<HR>
<A NAME="fig7-5">
<PRE>Figure 7-5.  Task Gate Indirectly Identifies Task</PRE>
<P>
<PRE>
         LOCAL DESCRIPTOR TABLE              INTERRUPT DESCRIPTOR TABLE
       +-------------------------+           +-------------------------+
       |                         |           |                         |
       |        TASK GATE        |           |        TASK GATE        |
       +------+-----+-----+------+           +------+-----+-----+------+
       |      |     |     |      |           |      |     |     |      |
       |------+-----+-----+------|           |------+-----+-----+------|
    +--|            |            |        +--|            |            |
    |  +------------+------------+        |  +------------+------------+
    |  |                         |        |  |                         |
    |  |                         |        |  |                         |
    |  +-------------------------+        |  +-------------------------+
    +----------------+  +-----------------+
                     |  |    GLOBAL DESCRIPTOR TABLE
                     |  |  +-------------------------+
                     |  |  |                         |
                     |  |  |     TASK DESCRIPTOR     |
                     |  |  +------+-----+-----+------+
                     |  |  |      |     |     |      |
                     |  +->|------+-----+-----+------|
                     +---->|            |            |--+
                           +------------+------------+  |
                           |                         |  |
                           |                         |  |
                           +-------------------------+  |
                                                        |
                           +-------------------------+  |
                           |                         |  |
                           |                         |  |
                           |                         |  |
                           |       TASK STATE        |  |
                           |         SEGMENT         |  |
                           |                         |  |
                           |                         |  |
                           |                         |  |
                           +-------------------------+<-+
</PRE>

<P>
<HR>
<P>
<B>up:</B> <A HREF="c07.htm">
Chapter 7 -- Multitasking</A><BR>
<B>prev:</B> <A HREF="s07_03.htm">7.3  Task Register</A><BR>
<B>next:</B> <A HREF="s07_05.htm">7.5  Task Switching</A>
</BODY>
